#pragma once
//#include <algorithm>
#include "Ray.h"
class BBox{
public:
	BBox(float _xmin, float _ymin, float _zmin, float _wmin, float _xmax, float _ymax, float _zmax, float _wmax);	//for individual shapes
	BBox(vec4 min, vec4 max);	//opposite corners of the box
	BBox();						//for groups where you don't know the size yet
	BBox(BBox _a, BBox _b);		//for combining two BBoxes
	~BBox();	

	float xmin(){ return thexmin; }
	void xmin(float _x){ thexmin = _x; }
	float ymin(){ return theymin; }
	void ymin(float _y){ theymin = _y; }
	float zmin(){ return thezmin; }
	void zmin(float _z){ thezmin = _z; }
	float wmin(){ return thewmin; }
	void wmin(float _w){ thewmin = _w; }
	float xmax(){ return thexmax; }
	void xmax(float _x){ thexmax = _x; }
	float ymax(){ return theymax; }
	void ymax(float _y){ theymax = _y; }
	float zmax(){ return thezmax; }
	void zmax(float _z){ thezmax = _z; }
	float wmax(){ return thewmax; }
	void wmax(float _w){ thewmax = _w; }

	vec4 minBound(){ return theMinBound; }
	vec4 maxBound(){ return theMaxBound; }
	//return a vec4 containing the bounding box's dimensions
	vec4 dimensions(){ return theMaxBound - theMinBound; }

	void addBBox(BBox _b);		//add a BBox to the bounds
	void addBBox(vec4 _min, vec4 _max);
	void addPoint(vec4 _pt);	//add a point to the bounds

	bool intersect(Ray *_theRay, float &_t0, float &_t1);

private:
	float thexmin, thexmax, theymin, theymax, thezmin, thezmax, thewmin, thewmax;
	vec4 theMinBound, theMaxBound;
	static vec4 maxVec(vec4 _a, vec4 _b){ return vec4(max(_a.x, _b.x), max(_a.y, _b.y), max(_a.z, _b.z), max(_a.w, _b.w)); }
	static vec4 minVec(vec4 _a, vec4 _b){ return vec4(min(_a.x, _b.x), min(_a.y, _b.y), min(_a.z, _b.z), min(_a.w, _b.w)); }

};

